package com.mingben.betplatform.main;

import com.mingben.betplatform.api.baoge3.Baoge3Api;
import com.mingben.betplatform.api.pk6758.Pk6758Api;
import com.mingben.betplatform.security.AuthorizationThread;
import com.mingben.betplatform.security.RSAUtils;
import java.util.Properties;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Scanner;
import java.util.Properties;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.mingben.betplatform.api.pk6758.BetStringFactory;
import com.mingben.betplatform.dto.baoge3.*;
import com.mingben.betplatform.dto.pk6758.OpenHistory;
import com.mingben.betplatform.enums.MoneyUnit;
import com.mingben.betplatform.exception.*;
import com.mingben.betplatform.thread.WinStopConditionThread;
import com.mingben.betplatform.util.*;
import com.mingben.betplatform.util.feifei.FeiFeiApi;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mingben.betplatform.main.Baoge3Main;
import java.io.*;
import java.time.LocalTime;
import java.time.temporal.ChronoField;
import java.util.*;
import java.util.stream.Collectors;


public class Baoge3Main {

    public static String configPath = "D:\\config.properties";

    public static void main(String[] args) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {

        //加密功能 管理员功能
        if(args != null){
            //
            if(args.length == 0){
                Properties configProperties = new Properties();
                //扫描固定文件xlsx
                if(!new File(configPath).exists()){
                    System.out.println("config file not exist {} "+ new File(configPath).getAbsolutePath());
                    return;
                }
                //载入配置文件
                configProperties.load(new FileReader(new File(configPath)));

                System.out.println(configProperties);

//                String username ="wy777888";
//                String password = "a12345678";


                Baoge3Api api = new Baoge3Api(configProperties);


                //TODO rsa加密　
                new AuthorizationThread().start();
                //止盈线程
                new WinStopConditionThread(api , configProperties.getProperty("zhiying") == null ?
                        Long.MAX_VALUE : Long.valueOf(configProperties.getProperty("zhiying"))).start();

                api.login();
                //等待用户输入 ...阻塞关闭
                Scanner sc = new Scanner(System.in);
                sc.next();
                return;
            }
            String time = args[0];
            if(time.length() != 13){
                return;
            }
            String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC892tA1mb5CcHr_xwjaGliYrgC-q9ECiSZKMzvMz-8-L8irHMYAjf3-TFFb5WLR3wYUs2fRhyzl53_4A9ei1vpKD4qdI1PfdTdh9kSgM4tqRmJCarfPFUMDa1ljIp8wFG6D94_nicqUMA3msLo8oQTAZpKImiZMRHIiqQImxPSCwIDAQAB";
            //加密
            String encode = RSAUtils.publicEncrypt(time, RSAUtils.getPublicKey(publicKey));
            System.out.println(encode);
            System.console().readLine();
            System.exit(0);
        }

    }

}
